<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>pchoct</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="pchmidinn.html" title="pchmidinn" />
    <link rel="next" href="pconvolve.html" title="pconvolve" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">pchoct</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="pchmidinn.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="pconvolve.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="pchoct"></a>
      <div class="titlepage"></div>
      <a id="IndexPchoct" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">pchoct</span>
        </h2>
        <p>pchoct — 
      Converts an octave-point-decimal value to pitch-class.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp133233600"></a>
        <h2>Description</h2>
        <p>
      Converts an octave-point-decimal value to pitch-class.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp133234832"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>pchoct</strong></span> (oct)  (init- or control-rate args only)</pre>
        <p>
      where the argument within the parentheses may be a further expression.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp133237392"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>pchoct</em></span> and its related opcodes are really <span class="emphasis"><em>value converters</em></span> with a special function of manipulating pitch data.
    </p>
        <p>
      Data concerning pitch and frequency can exist in any of the following forms:
    </p>
        <div class="table">
          <a id="idp133239904"></a>
          <p class="title">
            <strong>Table 20. Pitch and Frequency Values</strong>
          </p>
          <div class="table-contents">
            <table summary="Pitch and Frequency Values" border="0">
              <colgroup>
                <col />
                <col />
              </colgroup>
              <thead>
                <tr>
                  <th>Name</th>
                  <th>Abbreviation</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>octave point pitch-class (8ve.pc)</td>
                  <td>pch</td>
                </tr>
                <tr>
                  <td>octave point decimal</td>
                  <td>oct</td>
                </tr>
                <tr>
                  <td>cycles per second</td>
                  <td>cps</td>
                </tr>
                <tr>
                  <td>Midi note number (0-127)</td>
                  <td>midinn</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
        <br class="table-break" />
        <p>
      The first two forms consist of a whole number, representing octave registration, followed by a specially interpreted fractional part. For <span class="emphasis"><em>pch</em></span>, the fraction is read as two decimal digits representing the 12 equal-tempered pitch classes from .00 for C to .11 for B. For <span class="emphasis"><em>oct</em></span>, the fraction is interpreted as a true decimal fractional part of an octave. The two fractional forms are thus related by the factor 100/12. In both forms, the fraction is preceded by a whole number octave index such that 8.00 represents Middle C, 9.00 the C above, etc. Midi note number values range between 0 and 127 (inclusively) with 60 representing Middle C, and are usually whole numbers. Thus A440 can be represented alternatively by 440 (<span class="emphasis"><em>cps</em></span>), 69 (<span class="emphasis"><em>midinn</em></span>), 8.09 (<span class="emphasis"><em>pch</em></span>), or 8.75 (<span class="emphasis"><em>oct</em></span>). Microtonal divisions of the <span class="emphasis"><em>pch</em></span> semitone can be encoded by using more than two decimal places.
    </p>
        <p>
      The mnemonics of the pitch conversion units are derived from morphemes of the forms involved, the second morpheme describing the source and the first morpheme the object (result). Thus <span class="emphasis"><em>cpspch</em></span>(8.09) will convert the pitch argument 8.09 to its <span class="emphasis"><em>cps</em></span> (or Hertz) equivalent, giving the value of 440. Since the argument is constant over the duration of the note, this conversion will take place at i-time, before any samples for the current note are produced. 
    </p>
        <p>
      By contrast, the conversion <span class="emphasis"><em>cpsoct</em></span>(8.75 + k1) which gives the value of A440 transposed by the octave interval <span class="emphasis"><em>k1</em></span>. The calculation will be repeated every k-period since that is the rate at which <span class="emphasis"><em>k1</em></span> varies.
    </p>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note: Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
        The conversion from <span class="emphasis"><em>pch</em></span>, <span class="emphasis"><em>oct</em></span>, or <span class="emphasis"><em>midinn</em></span> into <span class="emphasis"><em>cps</em></span> is not a linear operation but involves an exponential process that could be time-consuming when executed repeatedly. Csound now uses a built-in table lookup to do this efficiently, even at audio rates. Because the table index is truncated without interpolation, pitch resolution when using one of these opcodes is limited to 8192 discrete and equal divisions of the octave, and some pitches of the standard 12-tone equally-tempered scale are very slightly mistuned (by at most 0.15 cents).
      </p>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="refsect1">
        <a id="idp133259760"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the pchoct opcode. It uses the file <a class="ulink" href="examples/pchoct.csd" target="_top"><em class="citetitle">pchoct.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp133261616"></a>
          <p class="title">
            <strong>Example 610. Example of the pchoct opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in</span>
-odac           -iadc    <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o pchoct.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="comment">; Initialize the global variables.</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">kr</span> <span class="op">=</span> 4410
<span class="ohdr">ksmps</span> <span class="op">=</span> 10
<span class="ohdr">nchnls</span> <span class="op">=</span> 1

<span class="comment">; Instrument #1.</span>
<span class="oblock">instr</span> 1
  <span class="comment">; Convert an octave-point-decimal value into a </span>
  <span class="comment">; pitch-class value.</span>
  ioct <span class="op">=</span> 8.75
  ipch <span class="op">=</span> <span class="opc">pchoct</span>(ioct)

  <span class="opc">print</span> ipch
<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="comment">; Play Instrument #1 for one second.</span>
<span class="stamnt">i</span> 1 0 1
<span class="stamnt">e</span>


<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />

      Its output should include a line like this:
      </p>
        <pre class="screen">instr 1:  ipch = 8.090</pre>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp133266608"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="cpsoct.html" title="cpsoct"><em class="citetitle">cpsoct</em></a>,
      <a class="link" href="cpspch.html" title="cpspch"><em class="citetitle">cpspch</em></a>,
      <a class="link" href="octcps.html" title="octcps"><em class="citetitle">octcps</em></a>,
      <a class="link" href="octpch.html" title="octpch"><em class="citetitle">octpch</em></a>,
      <a class="link" href="cpsmidinn.html" title="cpsmidinn"><em class="citetitle">cpsmidinn</em></a>,
      <a class="link" href="octmidinn.html" title="octmidinn"><em class="citetitle">octmidinn</em></a>,
      <a class="link" href="pchmidinn.html" title="pchmidinn"><em class="citetitle">pchmidinn</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp133274480"></a>
        <h2>Credits</h2>
        <p>Example written by Kevin Conder.</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="pchmidinn.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="pconvolve.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">pchmidinn </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> pconvolve</td>
        </tr>
      </table>
    </div>
  </body>
</html>
